package com.yuanqi.hnucshop.service.impl;

import com.yuanqi.hnucshop.entity.Goods;
import com.yuanqi.hnucshop.mapper.GoodsMapper;
import com.yuanqi.hnucshop.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    GoodsMapper goodsMapper;

    @Override
    public Boolean addGoods(Goods goods) {

        if (goods==null || goods.getGoodsId()==null) return false;

        Integer integer = goodsMapper.addGoods(goods);

        if (integer == 1) return true;

        else return false;
    }

    @Override
    public Boolean deleteGoods(int goodsId) {

        Integer integer = goodsMapper.deleteGoods(goodsId);

        if (integer == 1) return true;

        else return false;
    }

    @Override
    public Boolean updateGoods(Goods goods) {

        if (goods==null || goods.getGoodsId()==null) return false;

        Integer integer = goodsMapper.updateGoods(goods);

        if (integer == 1) return true;

        else return false;
    }

    @Override
    public Goods selectGoods(int goodsId) {

        Goods goods = goodsMapper.selectGoods(goodsId);

        return goods;
    }

    @Override
    public List<Goods> selectAllGoods() {

        List<Goods> goods = goodsMapper.selectAllGoods();

        return goods;
    }

    @Override
    public List<Goods> selectUserGoods(String openid) {

        List<Goods> goods = goodsMapper.selectUserGoods(openid);

        return goods;
    }
}
